﻿using Gonte.Wpf.Controls.ViewModel;

using Microsoft.VisualStudio.TestTools.UnitTesting;

using MyWpfControlsTest.Model;
using MyWpfControlsTest.ViewModel;

namespace MyWpfControlsTest
{
    [TestClass()]
    public class TreeViewItemViewModelTest
    {
        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion

        [TestMethod()]
        public void TreeViewItemViewModelAddChildTest()
        {
            ViewModelBase rootViewModel = new RootTreeItemViewModel();

            Assert.AreEqual("Root Item", rootViewModel.Label);

            RootTreeItem rootItem = (RootTreeItem)rootViewModel.Model;
            Assert.IsNull(rootItem.Name);

            ChildTreeItem item1 = new ChildTreeItem();
            item1.Name = "Item 1";

            ViewModelBase childViewModel1 = new ChildTreeItemViewModel(item1, rootViewModel);
            rootViewModel.AddChild(childViewModel1);

            Assert.AreEqual(1, rootViewModel.Children.Count);
            
        }

        [TestMethod()]
        public void TreeViewItemViewModelLoadChildrenTest()
        {
            ViewModelBase rootViewModel = new RootTreeItemViewModel();
            RootTreeItem rootItem = (RootTreeItem)rootViewModel.Model;

            for (int i = 0; i < 20; ++i)
            {
                ChildTreeItem childItem = new ChildTreeItem();
                childItem.Name = "Item " + (i + 1).ToString();

                rootItem.Children.Add(childItem);
            }

            Assert.AreEqual(0, rootViewModel.Children.Count);

            rootViewModel.LoadChildren();

            Assert.AreEqual(20, rootViewModel.Children.Count);

        }
    }
}
